﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DAL;
using Business.Classes;

namespace UI
{
    public partial class Login : System.Web.UI.Page
    {
        UsuarioBusiness userBusiness = new UsuarioBusiness();

        protected void Page_Load(object sender, EventArgs e)
        {
            lbMsg.Text = string.Empty;
        }

        protected void btLogin_Click(object sender, EventArgs e)
        {
            try
            {
                Usuario user = userBusiness.GetUsuarioByLoginAndPassword(
                    txtLogin.Text, txtPassword.Text);

                if (user != null)
                {
                    Session["user"] = user;
                    Response.Redirect(new Controlador.Controladora().GetHomePage());
                }
                else
                {
                    lbMsg.Text = "Login e/ou senha inválido!";
                }
            }
            catch (Exception)
            {
                lbMsg.Text = "Login e/ou senha inválido!";
            }
        }
    }
}
